﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;

namespace MisClient
{
    //登录账号信息
    [Serializable]
    public class UserInfo
    {
        public string UserCode { get; set; }
        public string Pass { get; set; }
        public string DeptCode { get; set; }
        public string Oper { get; set; }

        public static void SaveDisk(UserInfo userInfo)
        {
            //创建一个格式化程序的实例  
            IFormatter formatter = new BinaryFormatter();
            //创建一个文件流      
            Stream stream = new FileStream("accountUser", FileMode.OpenOrCreate, FileAccess.Write, FileShare.None);
            formatter.Serialize(stream, userInfo);
            stream.Close(); 
        }

        public static UserInfo FromDisk()
        {
            if (!File.Exists("accountUser"))
                return null;
            IFormatter formatter = new BinaryFormatter();
            //反序列化   
            Stream stream = new FileStream("accountUser", FileMode.Open,
                FileAccess.Read, FileShare.Read);
            var accountUser = (UserInfo)formatter.Deserialize(stream);
            stream.Close();
            return accountUser;
        }
    }
}
